home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / 3dscale_geom / hips.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-16  |  4.5 KB  |  251 lines

  1. /*
  2. *    hips: subroutine package to read and write hips images
  3. */
  4.  
  5. #include "hips.h"
  6. #include "simple.h"
  7. #include "pixel.h"
  8.  
  9. extern U_IMAGE    uimg;
  10.  
  11.  
  12. Hips*    hips_open(file, mode)
  13. char    *file, *mode;
  14. {
  15. Hips    *p;
  16.  
  17.     ALLOC_ZERO(p, Hips, 1);
  18.     strcpy(p->name, file);
  19.  
  20.     if (str_eq(mode, "r")) {    /* input file */
  21.     (*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, No);
  22.     uimg.o_form = uimg.in_form;
  23.     uimg.pxl_out = uimg.pxl_in;
  24.     if (uimg.dpy_channels==3)
  25.         uimg.color_form = CFM_SEPLANE;
  26.     uimg.frames += !uimg.frames;
  27.     if (uimg.in_type == HIPS)    {
  28.         if (uimg.in_form != IFMT_BYTE)
  29.             prgmerr(0, "warning: pixel format may not be byte\n");
  30.         uimg.o_type = HIPS;
  31.         uimg.o_form = IFMT_BYTE;
  32.     }
  33.     p->dx = uimg.width;
  34.     p->dy = uimg.height;
  35.     p->nchan = 1;        /* used for byte filter    */
  36.     } else {
  37.     p->dx = XMAX;
  38.     p->dy = YMAX;
  39.     p->nchan = uimg.dpy_channels;
  40.     }
  41.     p->ox = p->oy = 0;
  42. return p;
  43. }
  44.  
  45. /**********************************************/
  46. void
  47. hips_close(p)
  48. Hips     *p;
  49. {
  50. syserr("Not needed: using stdin and stdout \n");
  51. }
  52.  
  53. char     *
  54. hips_get_name(p)
  55. Hips     *p;
  56. {
  57. return    p->name;
  58. }
  59.  
  60. /****************************************/
  61. void
  62. hips_clear(p, pv)
  63. Hips     *p;
  64. Pixel1    pv;
  65. {
  66. }
  67.  
  68. void
  69. hips_clear_rgba(p, r, g, b, a)
  70. Hips    *p;
  71. Pixel1    r, g, b, a;
  72. {
  73. }
  74.  
  75. /*-------------------- file writing routines --------------------*/
  76. void
  77. hips_set_nchan(p, nchan)
  78. Hips     *p;
  79. int       nchan;
  80. {
  81.     p->nchan = nchan;
  82. }
  83.  
  84. /****************************************/
  85. void
  86. hips_set_box(p, ox, oy, dx, dy)
  87. Hips    *p;
  88. int    ox, oy, dx, dy;
  89. {
  90.     if (dx > XMAX || dy > YMAX)
  91.     prgmerr(2, "\nMaximum destination size is %d x %d \n\n",
  92.          XMAX, YMAX);
  93.     p->ox = ox;
  94.     p->oy = oy;
  95.     p->dx = dx;
  96.     p->dy = dy;
  97.     if (!p->ibuf)
  98.     verify_buffer_size(&p->ibuf, dx*dy, p->nchan, "h_set_box");
  99. }
  100.  
  101. /****************************************/
  102. void
  103. hips_write_pixel(p, x, y, pv)
  104. Hips    *p;
  105. int    x, y;
  106. Pixel1    pv;
  107. {
  108. prgmerr(1, "hips_write_pixel: unimplemented\n");
  109. }
  110.  
  111. void
  112. hips_write_pixel_rgba(p, x, y, r, g, b, a)
  113. Hips    *p;
  114. int    x, y;
  115. Pixel1    r, g, b, a;
  116. {
  117. prgmerr(1, "hips_write_pixel_rgba: unimplemented\n");
  118. }
  119.  
  120. /****************************************/
  121. void
  122. hips_write_row(p, y, x0, nx, buf)
  123. Hips    *p;
  124. int    y, x0, nx;
  125. register Pixel1    *buf;
  126. {
  127.  
  128. register int    i, offset = y * p->dx + x0;
  129.  
  130.     for (i = 0; i < nx; i++) {
  131.     p->ibuf[offset + i] = buf[i];
  132. /*    fprintf(stderr, " %d", buf[i]); */
  133.     }
  134. }
  135.  
  136. /****************************************/
  137. void
  138. hips_write_row_rgba(p, y, x0, nx, buf)
  139. Hips    *p;
  140. int    y, x0, nx;
  141. register Pixel1    *buf;
  142. {
  143. prgmerr(1, "hips_write_row_rgba: unimplemented\n");
  144. }
  145.  
  146. /****************************************/
  147. void
  148. hips_get_box(p, ox, oy, dx, dy)
  149. Hips    *p;
  150. int    *ox, *oy, *dx, *dy;
  151. {
  152.     *ox = p->ox;
  153.     *oy = p->oy;
  154.     *dx = p->dx;
  155.     *dy = p->dy;
  156. }
  157.  
  158. /*-------------------- file reading routines ------------------*/
  159.  
  160. hips_get_nchan(p)
  161. Hips    *p;
  162. {
  163.     return p->nchan;
  164. }
  165.  
  166. Pixel1
  167. hips_read_pixel(p, x, y)
  168. Hips    *p;
  169. int    x, y;
  170. {
  171. prgmerr(1, "hips_read_pixel: unimplemented\n");
  172. }
  173.  
  174. void
  175. hips_read_pixel_rgba(p, x, y, pv)
  176. Hips    *p;
  177. int    x, y;
  178. Pixel1    *pv;
  179. {
  180. prgmerr(1, "hips_read_pixel_rgba: unimplemented\n");
  181. }
  182.  
  183. /****************************************/
  184. void
  185. hips_read_row(p, y, x0, nx, buf)
  186. Hips    *p;
  187. int    y, x0, nx;
  188. Pixel1    *buf;
  189. {
  190. register int    i, offset = y * p->dx + x0;
  191.  
  192.     for (i = 0; i < nx; i++) {
  193.     buf[i] = p->ibuf[offset + i];
  194.     /* fprintf(stderr, " %d", buf[i]); */
  195.     }
  196.  
  197. }
  198.  
  199. /****************************************/
  200. void
  201. hips_read_row_rgba(p, y, x0, nx, buf)
  202. Hips    *p;
  203. int    y, x0, nx;
  204. Pixel1    *buf;
  205. {
  206. prgmerr(1, "hips_read_row_rgba: unimplemented\n");
  207. }
  208.  
  209. /****************************************/
  210. /* routines to load and save hips file */
  211. /****************************************/
  212. load_hips_frame(img, p)
  213. U_IMAGE    *img;
  214. Hips    *p;
  215. {
  216. int    w = img->width, h = img->height, tl;
  217.     img->load_all = 1;
  218.     img->width = p->dx;
  219.     img->height = p->dy;
  220.     img->src = p->ibuf;
  221.     tl = (*img->std_swif)(FI_LOAD_FILE, img, 0, 0);
  222.     p->ibuf = uimg.src;
  223.     img->width = w,    img->height = h;
  224.     if (tl > 0)    tl = p->dx * p->dy;    /* avoid errors    */
  225. return    tl;
  226. }
  227.  
  228. /****************************************/
  229. void    store_hips_frame(p)
  230. Hips     *p;
  231. {
  232. int    len = (uimg.width=p->dx) * (uimg.height=p->dy) * sizeof(*p->ibuf);
  233.  
  234. if (uimg.o_type == RLE)    {
  235. register Pixel1    *r=p->ibuf, *g=r+len, *b=g+len, *obp;
  236. register int    w = p->dx, ch3 = p->nchan==3;
  237. uimg.src = obp = nzalloc(len, p->nchan, "store_rle");
  238.     for (len=p->dy; len--;)    {
  239.         memcpy(obp, r, w);    obp += w;    r += w;
  240.         if (!ch3)    continue;
  241.         memcpy(obp, g, w);    obp += w;    g += w;
  242.         memcpy(obp, b, w);    obp += w;    b += w;
  243.     }
  244.     (*uimg.std_swif)(FI_SAVE_FILE, &uimg, 0, 0);
  245. free(uimg.src);
  246. uimg.src = 0;
  247. }
  248. else    if (fwrite(p->ibuf, p->nchan, len, stdout) != len)
  249.     syserr("error during write\n");
  250. }
  251.